/*
 * Copyright (c) 2023-2025 elsfs Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.elsfs.cloud.module.ai.biz.service;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pgvector.PgVectorEmbeddingStore;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/** 向量数据库初始化 */
@Configuration
@RequiredArgsConstructor
@SuppressWarnings("all")
public class EmbeddingStoreInit {

  //    @Bean
  //    public EmbeddingStore<TextSegment> initEmbeddingStore() {
  //        //使用redis作为向量数据库
  //        return RedisEmbeddingStore
  //          .builder()
  //                .host("localhost") // redis host
  //                .port(6379) // redis port
  //                .dimension(384) // 嵌入向量维度
  //                .indexName("langchain4j") // 索引名称
  //                .prefix("langchain4j:") // 前缀
  //                .build();
  //    }
  //    @Bean
  //    public EmbeddingStore<TextSegment> initEmbeddingStore() {
  //        //使用redis作为向量数据库
  //        return new InMemoryEmbeddingStore<>();
  //    }
  @Bean
  public EmbeddingStore<TextSegment> initEmbeddingStore() {
    // 使用redis作为向量数据库
    return PgVectorEmbeddingStore.builder()
        .createTable(true)
        .dropTableFirst(true)
        .host("localhost")
        .port(5432)
        .user("postgres")
        .password("Elsfs2023")
        .database("postgres")
        .table("postgres")
        .dimension(384)
        .build();
  }
}
